package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL执行DML语句
 */
public class JDBCDemo9 {
    public static void main(String[] args) {
        //完成注册功能
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎注册","注册");
        try (
                Connection connection = DBUtil.getConnection();
        ){
            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                         "VALUES(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2,userInfo.getPassword());
            ps.setString(3, userInfo.getNickname());
            ps.setInt(4,userInfo.getAge());
            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("注册成功");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}





